package application.models.models;

/**
 * This class takes care of storing information about any given entity's critical attributes in the data layer.
 * (set name, id attribute name, if applicable: a joined set name, and the names of the two attributes linking the main and joined set together)
 * 
 * @author Morten Therkildsen & Philip Rasmussen
 */
public class SetDescription {
	private String mainSetIdAttribute; // The name of the attribute defining the id of the model
	private String mainSetName;// The data set this model type is stored in
	private String joinedSetName; // The data set any extra attributes are stored in
	private String mainSetJoinAttribute; // The attribute in the main set used to find the additional attributes in the set described by joinedSetName
	private String joinedSetJoinAttribute; // The name of the attribute in the set described by joinedSetName that is referred to by mainSetJoinAttribute

	/**
	 * Creates an object containing information about an entity's data layer set name, any joined set name, the attribute defining the main set, and the two attributes that joins main set and joined set together.
	 * 
	 * @param mainSetIdAttribute	The name of the entity's ID attribute ("id", "customer_no", etc.). Cannot be null or empty
	 * @param mainSetName			The name of the set. Cannot be null or empty
	 * @param joinedSetName			The name of a set joined with the main set (optional). Cannot be empty
	 * @param mainSetJoinAttribute	The name of the attribute in the main set that is joined with one of the joined set's attributes. If joinedSetName is passed, this parameter cannot be null or empty
	 * @param joinedSetJoinAttribute	The name of the attribute in the joined set that is linked to the main set. If joinedSetName is passed, this parameter cannot be null or empty
	 */
	public SetDescription(String mainSetIdAttribute, String mainSetName, String joinedSetName, String mainSetJoinAttribute, String joinedSetJoinAttribute){

		if(mainSetIdAttribute == null) throw new NullPointerException("mainSetIdAttribute was null.");
		else if(mainSetIdAttribute.trim().length() == 0)
			throw new IllegalArgumentException("mainSetIdAttribute was empty.");

		if(mainSetName == null) throw new NullPointerException("mainSetName was null."); 
		else if(mainSetName.trim().length() == 0)
			throw new IllegalArgumentException("mainSetName was empty.");

		if(joinedSetName != null){

			if(joinedSetName.trim().length() == 0)	throw new IllegalArgumentException("joinedSetName was empty.");
			else if(mainSetJoinAttribute == null) throw new IllegalArgumentException("Passed joinedSetName without a mainSetJoinAttribute.");
			else if(joinedSetJoinAttribute == null) throw new IllegalAccessError("Passed joinedSetName without a joinedSetJoinAttribute");

			if(mainSetJoinAttribute.trim().length() == 0) throw new IllegalArgumentException("mainSetJoinAttribute was empty.");

			if(joinedSetJoinAttribute.trim().length() == 0)	throw new IllegalArgumentException("joinedSetJoinAttribute was empty.");
		}
		
		if(joinedSetName == null && mainSetJoinAttribute != null) throw new IllegalArgumentException("provided a mainSetJoin attribute wihtout a joinedSetName");
		if(joinedSetName == null && joinedSetJoinAttribute != null) throw new IllegalArgumentException("provided a joinedSetJoin attribute wihtout a joinedSetName");

		
		this.mainSetIdAttribute = mainSetIdAttribute;
		this.mainSetName = mainSetName;
		this.joinedSetName = joinedSetName;
		this.mainSetJoinAttribute = mainSetJoinAttribute;
		this.joinedSetJoinAttribute = joinedSetJoinAttribute;
	}

	/**
	 * The id attribute of the main set
	 * @return The id attribute of the main set
	 */
	public String getMainSetIdAttribute(){

		return mainSetIdAttribute;
	}

	/**
	 * The name of the main set
	 * @return The name of the main set
	 */
	public String getMainSetName(){

		return mainSetName;
	}

	/**
	 * The join attribute of the main set
	 * @return The join attribute of the main set
	 */
	public String getMainSetJoinAttribute(){

		return mainSetJoinAttribute;
	}

	/**
	 * The name of the joined set
	 * @return The name of the joined set
	 */
	public String getJoinedSetName(){

		return joinedSetName;
	}

	/**
	 * The join attribute of the joined set
	 * @return The join attribute of the joined set
	 */
	public String getJoinedSetJoinAttribute(){

		return joinedSetJoinAttribute;
	}
}
